package com.azhi.srb.base.config;

import com.google.common.base.Predicates;
import io.swagger.models.Path;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.function.Predicate;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()//过滤器，过滤请求路径，不同路径将展示不同swagger接口
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    public ApiInfo adminApiInfo(){
        return new ApiInfoBuilder().title("admin后台管理系统")
                .contact(new Contact("azhi","http://www.baidu.com","1217377380@qq.com"))
                .description("lajklfjkalkfjoaeuiojfroefnznvdzvodjabnf,dsfjaofhohaonaf")
                .version("1.2")
                .build();
    }

    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("webApi")
                .apiInfo(webApiInfo())
                .select()//过滤器，过滤请求路径，不同路径将展示不同swagger接口
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    public ApiInfo webApiInfo(){
        return new ApiInfoBuilder().title("web前台管理系统")
                .contact(new Contact("azhi","http://www.baidu.com","1217377380@qq.com"))
                .description("lajklfjkalkfjoaeuiojfroefnznvdzvodjabnf,dsfjaofhohaonaf")
                .version("1.2")
                .build();
    }
}
